<script setup lang="ts">
import { ref, watch, toRefs } from 'vue'

const props = defineProps({
  images: {
    type: Array,
    default: () => []
  },
  activeIndex: {
    type: Number,
    default: 0
  },
  Destory: {
    type: Function,
    default: () => {}
  }
})

const { images, activeIndex } = toRefs(props)

const show_dialog = ref<Boolean>(false)
const show_fn = ref<Boolean>(true)

// const images = ref(['BHPY1.jpg', 'BHPY2.jpg', 'BHPY3.jpg', 'BHPY4.jpg'])

// const activeIndex = ref<number>(0)

watch(
  () => activeIndex.value,
  (newVal) => {
    if (newVal < 0) {
      activeIndex.value = images.value.length - 1
    } else if (newVal >= images.value.length) {
      activeIndex.value = 0
    }
  }
)

watch(
  () => show_dialog.value,
  (newVal) => {
    if (newVal) {
      props.Destory()
    }
  }
)

const toggleFn = () => {
  show_fn.value = !show_fn.value
}
</script>

<template>
  <AlexBtn @click="show_dialog = true">按钮测试</AlexBtn>

  <AlexDialog
    v-model:show="show_dialog"
    :outside-close="true"
    top="50%"
    backdrop="rgba(48,55,66,0.3)"
  >
    <template #header></template>
    <template #default>
      <div class="viewer">
        <ul class="views">
          <template v-for="(image, index) in images" :key="index">
            <li title="双击隐藏功能栏" v-if="index === activeIndex">
              <img @dblclick="toggleFn" :src="`/ImageView/${image}`" />
            </li>
          </template>
        </ul>

        <div class="view-functions" v-show="show_fn">
          <div class="count">{{ activeIndex + 1 }} / {{ images.length }}</div>

          <div class="switch">
            <AlexBtn height="2rem" width="2rem" radius=".2rem" @click="activeIndex--">＜</AlexBtn>
            <AlexBtn height="2rem" width="2rem" radius=".2rem" @click="activeIndex++">＞</AlexBtn>
          </div>

          <div class="close">
            <AlexBtn height="2rem" width="2rem" radius=".2rem" @click="show_dialog = false"
              >✕</AlexBtn
            >
          </div>
        </div>
      </div>
    </template>
  </AlexDialog>
</template>

<style scoped lang="scss">
.alex-dialog {
  // overflow-y: scroll;
  scrollbar-width: none;
  --content-bg: transparent;
  background-color: transparent;
  height: 100%;
  box-shadow: unset;
  border-radius: unset;
  :deep(.dialog_ctr) {
    padding: 0rem !important;
    max-width: 100%;
    // max-height: calc(100% - 10rem);
    height: 100%;
  }
  :deep(.dialog_content) {
    height: 100%;
  }

  &::backdrop {
    backdrop-filter: blur(8px);
  }
}

ul {
  list-style-type: none;
}

.viewer {
  width: 100%;
  height: 100%;
  // position: relative;
  img {
    object-fit: contain;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0.2rem;
    cursor: pointer;
  }
  ul.views {
    display: flex;
    height: 100%;
    li {
      margin-bottom: 1rem;
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}

.view-functions {
  background-color: rgba(130, 136, 141, 0.75);
  color: #fff;
  bottom: 0;
  position: absolute;
  border-radius: 0.25rem;

  width: 100%;
  max-width: 30rem;

  padding: 0.55rem;
  box-sizing: border-box;

  display: flex;
  justify-content: space-between;
  align-items: center;

  left: 50%;
  transform: translateX(-50%);

  .alex-btn {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.2);
    &:hover {
      background-color: rgba(255, 255, 255, 0.5);
    }
    & + button {
      margin-top: unset !important;
      margin-left: 0.5rem;
    }
  }

  .count {
    display: flex;
    box-sizing: border-box;
    font-size: 0.95rem !important;
    margin-left: 0.5rem;
  }

  .switch {
    display: flex;
  }
}
</style>
